// Created by Ken   
// this class is the main class to test all the other class
// Be sure to include package board
//********************************************************
// Modified by Ayaz Maroof
// Date: 7 March 2012
// Changes: Changed the parameters for the eW.showQuestion and eW.showMC function call

import dice.*;
import event.*;

import java.util.Scanner;
import board.*;
import player.*;
public class mainBoard {
	// static variable
	// Hold the data in mainBoard.java due to pass buy value
	private static DummyBoard gameBoard ;
	private static int numberOfPlayer;
	private static Player[] playerArr;
	private static EventDatabase eventDataB;
	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		// Set Up
		eventDataB = new EventDatabase();
		PlayerIO io = new PlayerIO();
		io.getInput(playerArr, gameBoard);
		
		numberOfPlayer = io.getNumOfPlayer();
		// Call control class  set up method to set up 
		PlayerDataProcessor processor = new PlayerDataProcessor();
		processor.setUp(numberOfPlayer);
		gameBoard = processor.getTemdB();
		playerArr = processor.getTemPArr();
		System.out.println("There are " + playerArr.length + " number of player.");
		System.out.println("Below are the info: ");
		io.printPlayerArr(playerArr);
		
		Move moveP = new Move();
		moveP.updateBoard(playerArr);
		gameBoard= moveP.getTemBoard();
		
		PrintTable pT = new PrintTable();
		pT.repaint(gameBoard);
		System.out.println("Set up process: DONE!");
		// Setup Done
		
		
		String ans;
		do {
			// Now it is rolling the dice
			for(int l=0; l<numberOfPlayer; l++) {
				DiceWindow  diceW = new DiceWindow();
				// Roll the first player
				diceW.rollSinglePlayer(playerArr[l], playerArr ,gameBoard);
				
				// update playerArr and game Board
				playerArr = diceW.getTemPArr();
				gameBoard = diceW.getTemB();
				
				// If hit on a cell which is event
				// Something happen here
				if(gameBoard.getCellType()[playerArr[l].getCell()].equals("E")){
					EventWindow eW = new EventWindow();
					eW.greet();
					eW.showQuestion(eventDataB, eW.getPickedEvent().getEventID());
					eW.showMC(eventDataB, eW.getPickedEvent().getEventID());
					int userAns;
					do {
						System.out.println("Now answer the question:(type in 1/2/3...\n)");
						Scanner ss = new Scanner(System.in);
						userAns = ss.nextInt();
					}while (userAns <0 ||  userAns > eW.getPickedEvent().getScore().length );
					EventController eC = new EventController();
					int pointsChange = eC.marker(userAns, eW.getPickedEvent());
					
					// update user points
					eC.updateSEPoints(playerArr[l], pointsChange);
					playerArr[l] = eC.gettemPlayer();
					
					// show player updated status
					System.out.println("\nSE Points Changed!");
					PlayerIO print = new PlayerIO();
					print.printSinglePlayerInfo(playerArr[l]);
					
					System.out.println("Event Stop here.");
					System.out.println("**************************************");
				}
			}
			System.out.println("Do you want to continue for the next round? (y/n) ");
			
			Scanner s = new Scanner(System.in);
			ans = s.next();
			
		}while(ans.equals("y") || ans.equals("Y"));
		
		System.out.println("GAME OVER!");
	}
}
